package com.irdstudio.efp.esb.service.impl.zx;

import com.alibaba.fastjson.JSONObject;
import com.irdstudio.basic.framework.core.exception.ESBException;
import com.irdstudio.basic.framework.core.util.SpringContextUtils;
import com.irdstudio.efp.esb.common.constant.MsLoanConstant;
import com.irdstudio.efp.esb.service.bo.req.MsYxApproveReqBean;
import com.irdstudio.efp.esb.service.bo.resp.MsYxApproveRespBean;
import com.irdstudio.efp.esb.service.client.ESBClientFactory;
import com.irdstudio.efp.esb.service.client.impl.MSESBBeanCreator;
import com.irdstudio.efp.esb.service.facade.zx.MsYxApprService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 需求编号：xxxxxx<br/>
 * 问题编号：<br/>
 * 功能描述：此类作废：改用通用带重试接口调用用信审批<br/>
 * 创建时间：2020/5/16 19:39
 * @Author tiankg
 * @Version 1.0
 * @Since 1.0
 */
@Service("msYxApprService+1")
public class MsYxApprServiceImpl implements MsYxApprService {

    private static Logger logger = LoggerFactory.getLogger(MsYxApprServiceImpl.class);

    @Override
    public MsYxApproveRespBean msYxAppr(MsYxApproveReqBean msYxApproveReqBean) throws ESBException {
        logger.info("======>调用马上金融联合贷用信审批接口【" + msYxApproveReqBean.getQryRptsInfArrys().get(0).getAppNo() + "_30220006_05】开始<======");
        MsYxApproveRespBean msYxApproveRespBean = null;
        try {
            msYxApproveRespBean = ESBClientFactory.buildClient().withBody(msYxApproveReqBean).withTradeNo(MsLoanConstant.TRADE_NO_30220006)
                    .withScene(MsLoanConstant.SCENE_05)
                    .withESBBeanFactory((MSESBBeanCreator) SpringContextUtils.getBean("MSESBBeanCreator"))
                    .create().sendAndReceive().getBody(MsYxApproveRespBean.class);
            if(msYxApproveRespBean!=null) {
                if(MsLoanConstant.RetCodeEnum.SUCCESS.VALUE.equals(msYxApproveRespBean.getQryRptsInfArry().get(0).getRcvSt())){
                    logger.info("调用马上金融联合贷用信审批接口【30220006_05】成功，返回信息：" + JSONObject.toJSONString(msYxApproveRespBean));
                    return msYxApproveRespBean;
                }
            }

        } catch (Exception e) {
            logger.error("调用马上金融联合贷用信审批接口【30220006_05】出现异常：" + e.getMessage());
            throw new ESBException("调用马上金融联合贷用信审批接口【30220006_05】出现异常：" + e.getMessage());
        } finally {
            logger.info("======>调用马上金融联合贷用信审批接口【" + msYxApproveReqBean.getQryRptsInfArrys().get(0).getAppNo() + "_30220006_05】结束<======");
        }
        return null;
    }
}
